package com.hmyd.hmyd_android.ui;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.AppBasic;
import com.hmyd.hmyd_android.adapter.InvestmentDescriptionAdapter;
import com.hmyd.hmyd_android.commons.UrlConstant;
import com.hmyd.hmyd_android.dto.InvestmentDescription;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_investment_description)
public class InvestmentDescriptionActivity extends BasicActivity{
	@ViewInject(R.id.home_title)
	public View home_title;
	@ViewInject(R.id.home_title_txt)
	public TextView home_title_txt;
	@ViewInject(R.id.home_right)
	public TextView home_right;
	
	@ViewInject(R.id.elist)
	private ExpandableListView elist;
	
	private static final String INTENT_TYPE_ID = "itemId";
	private String itemId;
	
	private final int DESCRIPTION = 1;

	public static Intent getIntent(Context context,String id){
		Intent intent = new Intent(context,InvestmentDescriptionActivity.class);
		intent.putExtra(INTENT_TYPE_ID, id);
		return intent;
	}
	
	private void onRequest(){
		RequestParams params = new RequestParams();
		params.addBodyParameter("itemId", itemId);
		onRequest(DESCRIPTION, UrlConstant.GETDESCRIPTION, HttpMethod.GET, params);
	}

	public void onPostSuccess(int postId, String result) {
		Gson gson = new Gson();
		java.lang.reflect.Type type2 = new TypeToken<List<InvestmentDescription>>() {}.getType();
		List<InvestmentDescription> list = gson.fromJson(result, type2);
		
		if(list!=null && list.size()>0){
			elist.setAdapter(new InvestmentDescriptionAdapter(this,list));
		}
	}

	@Override
	protected void setParams() {
		home_title_txt.setText(getString(R.string.title_investment_description));
		home_title.setOnTouchListener(touch);
		
		itemId = getIntent().getStringExtra(INTENT_TYPE_ID);
		
		elist.setGroupIndicator(null);
		onRequest();
	}

	@Override
	protected void leftButton() {
		AppBasic.getInstance().finishCurrentActivity();
	}

	@Override
	protected void rightButton() {
		
	}

	@Override
	public void onPostFailure(int postId, String msg) {
		
	}

}
